package com.polaris.live.adapter.view_holder

import android.view.View
import androidx.lifecycle.LifecycleCoroutineScope
import com.bumptech.glide.Glide
import com.polaris.live.databinding.AdapterHomeListGameBinding
import com.polaris.live.resp.back_resp.GameVo
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.playAsync
import com.polaris.live.widget.refresh.BaseBindingViewHolder
import org.libpag.PAGScaleMode

/**
 * 列表数值游戏viewHolder
 */
class HomeListGameViewHolder(
    binding: AdapterHomeListGameBinding,
    private val lifecycleScope: LifecycleCoroutineScope
) : BaseBindingViewHolder<AdapterHomeListGameBinding, GameVo>(binding) {

    override fun bind(item: GameVo) {
        mBinding.apply {
            Glide.with(root.context)
                .load(ImageUtils.imgPath(item.iconRound))
                .into(ivCover)
            ivCover.visibility = View.VISIBLE

            pagCover.playAsync(lifecycleScope, item.animation) {
                setScaleMode(PAGScaleMode.Zoom)
                setRepeatCount(-1)

                ivCover.visibility = View.GONE
            }
            tvGameName.text = item.name
            tvUserDetail.text = item.listSlogan
            Glide.with(root.context)
                .load(ImageUtils.imgPath("static/state/numerical_game_background.png"))
                .into(ivRoomTypeCover)
        }
    }
}